package com.ymf.consumer.controller;

import com.ymf.consumer.client.MyClient;
import com.ymf.consumer.pojo.Description;
import com.ymf.consumer.pojo.MyMessage;
import com.ymf.consumer.pojo.Skills;
import com.ymf.consumer.pojo.data;
import com.ymf.consumer.util.Value;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@RequestMapping("cf")
public class ConsumerFeignController {

    @Autowired
    @SuppressWarnings("all")
    private MyClient myClient;

    @GetMapping("all")
    public List<MyMessage> findall(){
//        Value<MyMessage> value = new Value<>();
//        value.setMessage(myClient.findall());
//        System.out.println(value);
        return myClient.findall();
    }
    @GetMapping("desc/{id}")
    public String desc(@PathVariable int id){
//        Value<MyMessage> value = new Value<>();
//        value.setMessage(myClient.findall());
//        System.out.println(value);
        return myClient.desc(id);
    }
    @PostMapping("updataAboutMe")
    public Value<Integer> updataAboutMe(@RequestBody MyMessage myMessage){
        Value<Integer> value = new Value<>();
        value.setStatus(200);
        value.setMessage(myClient.updataAboutMe(myMessage));
        return value;
    }
    @PostMapping("updatamy_message")
    public Value<Integer> updataMy_message(@RequestBody MyMessage myMessage){
        Value<Integer> value = new Value<>();
        value.setStatus(200);
        value.setMessage(myClient.updataMy_message(myMessage));
        return value;
    }
    @GetMapping("findskills")
    public String findskills(){
        return myClient.findskills();
    }
    @GetMapping("deleteskillsbyid/{id}")
    public Value<Integer> deleteSkillsById(@PathVariable int id){
        Value<Integer> value = new Value<>();
        value.setStatus(200);
        value.setMessage(myClient.deleteSkillsById(id));
        value.setStatusText("删除成功");
        return value;
    }
    @PostMapping("insertskills")
    public Value<Integer> insertSkills(@RequestBody Skills skills){
        Value<Integer> value = new Value<>();
        value.setStatus(200);
        value.setMessage(myClient.insertSkills(skills));
        return value;
    }
    @PostMapping("updateskills")
    public Value<Integer> updateSkillsById(@RequestBody Skills skills){
        Value<Integer> value = new Value<>();
        value.setStatus(200);
        value.setMessage(myClient.updateSkillsById(skills));
        return value;
    }
    @PostMapping("updatasignature")
    public Value<Integer> updataSignature(@RequestBody MyMessage myMessage){
        Value<Integer> value = new Value<>();
        value.setStatus(200);
        value.setMessage(myClient.updataSignature(myMessage));
        return value;
    }
    @PostMapping("deleteescription")
    public Value<Integer> deleteEscription(@RequestBody Description description){
        Value<Integer> value = new Value<>();
        value.setStatus(200);
        value.setMessage(myClient.deleteEscription(description));
        return value;
    }
    @PostMapping("insertdescription")
    public Value<Integer> insertDescription(@RequestBody Description description){
        Value<Integer> value = new Value<>();
        value.setStatus(200);
        value.setMessage(myClient.insertDescription(description));
        return value;
    }
    @PostMapping("updatenotice")
    public Value<Integer> updateNotice(@RequestBody MyMessage myMessage){
        Value<Integer> value = new Value<>();
        value.setStatus(200);
        value.setMessage(myClient.updateNotice(myMessage));
        return value;
    }
    @org.springframework.beans.factory.annotation.Value("${file.path}")
    private String path;
    @PostMapping("uodateavatar")
    public Value<Integer> uodateAvatar(@RequestBody MyMessage myMessage){
        myMessage.setAvatar("http://127.0.0.1:10001/file/"+myMessage.getAvatar());
        Value<Integer> value = new Value<>();
        value.setStatus(200);
        value.setMessage(myClient.uodateAvatar(myMessage));
        return value;
    }

    @GetMapping("redis")
    public Value<String> findredis(){
        Value<String> value = new Value<>();
        value.setStatus(200);
        value.setMessage(myClient.findredis());
        return value;
    }
}
